<?php
#DP 03-05-2012
/**
 * Przedstawienie dzialania paginacji
 * @author damian
 *
 */
class TestPaginacjaController extends Zend_Controller_Action
{
	private $db=null;
	private $bootstrap=null;
	
	/**
	 * 
	 */
    public function init()
    {
		$this->bootstrap = $this->getInvokeArg('bootstrap');
	    $this->db=$this->bootstrap->getResource('db');
    }

    # Najprostsza paginacja przekazuje tablice
    public function indexAction()
    {
    	// Create an array with numbers 1 to 100
		$data = range(1, 100);
 
		// Get a Paginator object using Zend_Paginator's built-in factory.
		$paginator = Zend_Paginator::factory($data);
		
		echo'<ul>';
		#
		// Select the second page
		#
		$paginator->setCurrentPageNumber(2);

	    // Render each item for the current page in a list-item
	    foreach ($paginator as $item) 
	    {
	       echo '<li>' . $item . '</li>';
	    }
	 
	    echo'</ul>';
    }

 	# 2012-05-05
 	# Widok paginacji w prtialu 
    public function paginacjapartialAction()
    {
    #
  // Setup pagination control view script. See the pagation control tutorial page
#
        // for more information about this view script.
#
        Zend_View_Helper_PaginationControl::setDefaultViewPartial('paginacja.phtml');
#
 
#
        // Fetch an already instantiated database connection from the registry
#
       
#
 
#
        // Create a select object which fetches blog posts, sorted decending by date of creation
#
        $select = $this->db->select()->from('city');
#
 
#
        // Create a Paginator for the blog posts query
#
        $paginator = Zend_Paginator::factory($select);
#
 
#
        // Read the current page number from the request. Default to 1 if no explicit page number is provided.
#
        $paginator->setCurrentPageNumber($this->_getParam('Name', 1));
#
 
#
        // Assign the Paginator object to the view
#
        $this->view->paginator = $paginator;

    
       echo '<br>paginacjaBaza';
       $this->render('index');
    }
   
    
    /**
     * 2012-05-05 
     * Nie dziala nic mi nie pobiera z  bazy nie wiem dlaczego niby mailo by to dzialac !!!
     */
    # Najprostsza paginacja przekazuje tablice
    public function paginacjabazaAction()
    {
      // Create a select query. $db is a Zend_Db_Adapter object, which we assume
      // already exists in your script.
      $select = $this->db->select()->from('city')->order('Name DESC');
      // Get a Paginator object using Zend_Paginator's built-in factory.
      $paginator = Zend_Paginator::factory($select);
      // Select the second page
      $paginator->setCurrentPageNumber(2);
	  echo'<ul>';

	  Application_Model_Narzedziowe_CVarDumper::dodaj($paginator,'Paginator');
	  
      // Render each the title of each post for the current page in a list-item
      /*
      foreach ($paginator as $item) 
      {
          echo '<li>'.$item->name.'</li>';
      }
      */
	  echo $this->paginator;
	  //echo $this->view->paginationControl($this->paginator, 'Elastic', 'paginacja.phtml');
      echo'</ul>';
      
      echo 'Akcja test';
      $this->render('index');
    }  
}

